package com.qqtech.qquan.homemaking.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.qqtech.core.common.util.BeanUtil;
import com.qqtech.core.frame.dao.BaseDaoImpl;
import com.qqtech.core.frame.dao.SqlId;
import com.qqtech.qquan.homemaking.model.HomemakingBase;
import com.qqtech.qquan.homemaking.model.HomemakingBaseVo;

@Repository
public class HomemakingBaseDaoImpl extends BaseDaoImpl<HomemakingBase> implements HomemakingBaseDao {
	public static final Logger log = LoggerFactory.getLogger(HomemakingBaseDaoImpl.class);

	@Override
	public int queryCountByType(HomemakingBase query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectCountByType"), BeanUtil.toMap(query));
	}

	@Override
	public Page<HomemakingBaseVo> queryPageListByType(HomemakingBase query,
			Pageable pageable) {
		List<HomemakingBaseVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectByType"), getParams(query, pageable));
		return new PageImpl<HomemakingBaseVo>(contentList, pageable, this.queryCountByType(query));
	}

	@Override
	public Page<HomemakingBaseVo> queryPageListAdmin(HomemakingBase query,
			Pageable pageable) {
		List<HomemakingBaseVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectAdminByType"), getParams(query, pageable));
		return new PageImpl<HomemakingBaseVo>(contentList, pageable, this.queryCountAdmin(query));
	}

	@Override
	public int queryCountAdmin(HomemakingBase query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectCountAdminByType"), BeanUtil.toMap(query));
	}

	@Override
	public int addOrderedCount(Integer id) {
		if (id == null || id.intValue() == 0) {
			return 0;
		}
		HomemakingBase query = new HomemakingBase();
		query.setId(id);
		return sqlSessionTemplate.update(getSqlName("addOrderedCount"), query);
	}

	@Override
	public int queryCountByCanServise(HomemakingBase query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectCountByCanService"), BeanUtil.toMap(query));
	}

	@Override
	public Page<HomemakingBaseVo> queryPageListByCanServise(
			HomemakingBase query, Pageable pageable) {
		List<HomemakingBaseVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectByCanService"), getParams(query, pageable));
		return new PageImpl<HomemakingBaseVo>(contentList, pageable, this.queryCountByCanServise(query));
	}
	
}
